package de.grosjohann.android.feuerwehr.domain;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import de.grosjohann.android.feuerwehr.type.FMSStatusType;

public class Fahrzeug
  implements Serializable {

  private final String identifier;
  private final String description;
  private final FMSStatusType status;

  private final Date changeDate;

  public Fahrzeug(JSONObject jsonObj) throws JSONException {
    identifier = jsonObj.getString("kennung");
    description = jsonObj.getString("bezeichnung");

    status = FMSStatusType.valueOf(jsonObj.getInt("status"));

    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
      changeDate = fmt.parse(jsonObj.getString("changeDate"));
    } catch (ParseException ex) {
      throw new JSONException(ex.getMessage());
    }
  }

  public FMSStatusType getStatus() {
    return status;
  }

  public String getIdentifier() {
    return identifier;
  }

  public String getDescription() {
    return description;
  }

  public Date getChangeDate() {
    return changeDate;
  }

  @Override
  public String toString() {
    return identifier + ": " + status.name();
  }
}
